import { createSlice } from "@reduxjs/toolkit";

//创建一个计数store
export const counterStore = createSlice({
  name: "count",
  //vuex中的state
  initialState: {
    list: [],
    num: 0,
    token: "fads97a9as9fas9d",
  },
  //vuex中的mutations
  reducers: {
    add: (state) => {
      state.num = state.num + 1;
    },
    jian: (state) => {
      state.num = state.num - 1;
    },
    changeValue: (state, action) => {
      console.log("action:", action);
      state.num = state.num + action.payload;
    },
  },
});

export const { add, jian, changeValue } = counterStore.actions;

export default counterStore.reducer;
